package com.zhairuihao.blog;

import com.zhairuihao.common.model.Blog;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/**
 * 本 demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法
 * 详见 JFinal 俱乐部: http://jfinal.com/club
 * 
 * BlogValidator.
 */
public class BlogValidator extends Validator {
	
	@Override
	protected void validate(final Controller controller) {
		validateRequiredString("blog.title", "titleMsg", "请输入Blog标题!");
		validateRequiredString("blog.content", "contentMsg", "请输入Blog内容!");
	}
	
	@Override
	protected void handleError(final Controller controller) {
		controller.keepModel(Blog.class);
		
		final String actionKey = getActionKey();
		if (actionKey.equals("/blog/save")) {
			controller.render("add.html");
		} else if (actionKey.equals("/blog/update")) {
			controller.render("edit.html");
		}
	}
}
